package com.salesmanager.core.business.book;

import com.salesmanager.core.business.common.model.audit.AuditListener;
import com.salesmanager.core.business.common.model.audit.AuditSection;
import com.salesmanager.core.business.common.model.audit.Auditable;
import com.salesmanager.core.business.generic.model.SalesManagerEntity;
import com.salesmanager.core.business.product.Product;

import javax.persistence.*;
import java.io.InputStream;
import java.util.Date;

@Entity
@EntityListeners(value = AuditListener.class)
@Table(name = "BOOK",uniqueConstraints = {
        @UniqueConstraint(columnNames = {"BOOK_CODE"})
})
public class Book extends SalesManagerEntity<Long,Product> implements Auditable {

    @Override
    public String toString() {
        return "Book{" +
                "id=" + id +
                ", bookCode='" + bookCode + '\'' +
                ", bookName='" + bookName + '\'' +
                ", startTime=" + startTime +
                ", endTime=" + endTime +
                ", bookDesc='" + bookDesc + '\'' +
                ", imagName='" + imagName + '\'' +
                ", author='" + author + '\'' +
                ", title='" + title + '\'' +
                ", status=" + status +
                ", count=" + count +
                ", imagInputStream=" + imagInputStream +
                '}';
    }

    @Id
    @Column(name = "BOOK_ID", unique=true, nullable=false)
    @TableGenerator(name = "TABLE_GEN", table = "SM_SEQUENCER", pkColumnName = "SEQ_NAME", valueColumnName = "SEQ_COUNT",
            pkColumnValue = "BOOK_NEXT_VAL",initialValue = 100000, allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.TABLE, generator = "TABLE_GEN")
    private Long id;


    //id, code , name , startTime, endTime, desc，picture(阿里云的oss存储)，count
    @Column(name = "BOOK_CODE",columnDefinition = "VARCHAR(10) COMMENT '图书编码'")
    private String bookCode;

    @Column(name = "BOOK_NAME",columnDefinition = "VARCHAR(10) COMMENT '图书名称'")
    private String bookName;

    @Column(name = "START_TIME",columnDefinition = "VARCHAR(30) COMMENT '开始时间'")
    private Date startTime;

    @Column(name = "END_TIME",columnDefinition = "VARCHAR(30) COMMENT '结束时间'")
    private Date endTime;

    @Column(name = "BOOK_DESC",columnDefinition = "VARCHAR(10) COMMENT '图书描述'")
    private String bookDesc;

    @Column(name = "IMAG_NAME",columnDefinition = "VARCHAR(10) COMMENT '图片名称'")
    private String imagName;

    @Column(name = "AUTHOR",columnDefinition = "VARCHAR(10) COMMENT '作者'")
    private String author;

    @Column(name = "TITLE",columnDefinition = "VARCHAR(10) COMMENT '标题'")
    private String title;

    @Column(name = "STATUS",columnDefinition = "INT(1) COMMENT '状态 0:无效 1:有效'")
    private Integer status = 1;

    @Column(name = "COUNT",columnDefinition = "VARCHAR(10) COMMENT '库存'")
    private Integer count;

    public Integer getCount() {
        return count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    @Transient
    private InputStream imagInputStream;

    public String getBookCode() {
        return bookCode;
    }

    public void setBookCode(String bookCode) {
        this.bookCode = bookCode;
    }

    public String getBookName() {
        return bookName;
    }

    public void setBookName(String bookName) {
        this.bookName = bookName;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public String getBookDesc() {
        return bookDesc;
    }

    public void setBookDesc(String bookDesc) {
        this.bookDesc = bookDesc;
    }

    public String getImagName() {
        return imagName;
    }

    public void setImagName(String imagName) {
        this.imagName = imagName;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public InputStream getImagInputStream() {
        return imagInputStream;
    }

    public void setImagInputStream(InputStream imagInputStream) {
        this.imagInputStream = imagInputStream;
    }




    @Override
    public AuditSection getAuditSection() {
        return null;
    }

    @Override
    public void setAuditSection(AuditSection audit) {

    }

    @Override
    public Long getId() {
        return id;
    }

    @Override
    public void setId(Long id) {
        this.id = id;
    }
}
